<?php require("inc/common.inc.php");
$web_title = "预约评价";
if($type == 'ajax'){
	$str=" and isok=1";
	if(empty($pageindex)){
		$pageindex=2;
	}
	$pagesize=intval($pagesize);
	if ($pagesize==0){
		$pagesize=8;
	}
	$order="order by adddate desc, id desc";
	$column=" * ";
	$biaoid="id";
	$list=$db->list1($pageindex,$pagesize,'mx_app_comment',$column,$str,$order,$biaoid);

	$status = 0;
	if($list){
		$status = 1;
	}
	print_r(json_encode(array('status'=>$status,'data'=>$list)));
	exit();
}
if ($actions=="setly"){
	if(empty($_COOKIE['userid']) || $_COOKIE['userid']=="" || empty($_COOKIE['username']) || $_COOKIE['username']==""){
		$return["success"]=false;
  		$return["msg"]="您需要登录后才可以预约评价。";
  		echo json_encode($return);
		exit();
	}else{
		$mxuserid = $_COOKIE['userid'];
		$mxusername = $_COOKIE['username'];
		$mxnickname = $_COOKIE['nickname'];
		
		$reservecommentnum = $db->getsingle("select reservecommentnum from mx_app_user where id=".$mxuserid);
		if($reservecommentnum<1){
			$return["success"]=false;
			$return["msg"]="您需要预约成功后才可以评价。";
			echo json_encode($return);
			exit();
		}
	}
  $return="";
  if($clerkname==""){
  	$return["success"]=false;
  	$return["msg"]="请选择您需要评价的种类";
	echo json_encode($return);
  	exit();
  }
  if($yname==""){
  	$return["success"]=false;
    $return["msg"]="姓名不能为空";
	echo json_encode($return);
    exit();
  }
  if($tel==""){
  	$return["success"]=false;
    $return["msg"]="联系电话不能为空";
	echo json_encode($return);
    exit();
  }
 if($content==""){
 	$return["success"]=false;
   $return["msg"]="内容不能为空";
	echo json_encode($return);
	exit();
 }
 $content=dvHTMLEncode($content);
  
  $files=array(
  		"clerkname"=>$clerkname,
        "yname"    =>$yname,
        "tel"      =>$tel,
        "email"    =>$email,
        "qq"       =>$qq,
        "content"  =>$content,
        "adddate"  =>date("Y-m-d H:i:s"),
  );
  $db->exe_insert("mx_app_comment",$files);
  $db->exe_update('mx_app_user', array('reservecommentnum'=>'reservecommentnum-1'),"id=".$mxuserid);
  //积分增加
  addIntegral(5, $mxuserid, '预约评价');
  $return["success"]=true;
  $return["msg"]="评价信息提交成功，谢谢您！";
  echo json_encode($return);
  exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" name="viewport">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><?php echo $web_title?></title>
<meta name="searchtitle" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<meta name="description" content="<?php echo $web_title2.$webdb['webdsc'];?>">
<meta name="keywords" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<link href="images/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="images/message.css" media="all" />
</head>
<script language="javascript" src="js/jquery_min.js"></script>
<!--[if lte IE 9]><script src="js/watermark.js"></script><![endif]-->
<script type="text/javascript"> 
		$(document).ready(function () { 
			$("#showcard1").click(function () {
				var btn = $(this);
				var clerkname = $("#clerkname").val();
				if (clerkname  == '') {
					alert("请选择店员");
					$("#clerkname").focus();
					return;
				}
				var yname = $("#yname1").val();
				if (yname  == '') {
					alert("请输入姓名");
					$("#yname1").focus();
					return;
				}
				var tel = $("#tel1").val();
// 				if (tel  == '') {
// 					alert("请输入联系电话");
// 					$("#tel1").focus();
// 					return;
// 				}
// 				else{
// 					var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/; 
// 					if(!pattern.test(tel)) 
// 					{ 
// 						alert("联系电话格式错误");
// 						$("#tel2").focus();
// 						return;
// 					} 
// 				}
				var email = $("#email1").val();
				var qq = $("#qq1").val();
				var content = $("#content1").val();
				if (content == '') {
					alert("请输入评价内容");
					$("#content1").focus();
					return;
				}
				var submitData = {
					clerkname:clerkname,
					yname:yname,
					tel:tel,
					email:email,
					qq:qq,
					content: content,
					actions: "setly",
				};
				$.post('#', submitData,
					function(data) {
						if (data.success == true) {
							alert(data.msg);
							setTimeout('window.location.href=location.href',1000);
						return;
					} else {
						alert(data.msg);
					}
				},
				"json")
			}); 
			//
			$("#showcard2").click(function () { 
				var btn = $(this);
				var clerkname = $("#clerkname2").val();
				if (clerkname  == '') {
					alert("请选择店员");
					$("#clerkname2").focus();
					return;
				}
				var yname = $("#yname2").val();
				if (yname  == '') {
					alert("请输入姓名");
					$("#yname2").focus();
					return;
				}
				var tel = $("#tel2").val();
// 				if (tel  == '') {
// 					alert("请输入联系电话");
// 					$("#tel2").focus();
// 					return;
// 				}
// 				else{
// 					var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/; 
// 					if(!pattern.test(tel)) 
// 					{ 
// 						alert("联系电话格式错误");
// 						$("#tel2").focus();
// 						return;
// 					} 
// 				}
				var email = $("#email2").val();
				var qq = $("#qq2").val();
				var content = $("#content2").val();
				if (content == '') {
					alert("请输入评价内容");
					$("#content2").focus();
					return;
				}
				var submitData = {
					clerkname:clerkname,
					yname:yname,
					tel:tel,
					email:email,
					qq:qq,
					content: content,
					actions: "setly",
				};
				$.post('#', submitData,
					function(data) {
						if (data.success == true) {
						alert(data.msg);
						setTimeout('window.location.href=location.href',1000);
						return;
					} else {}
				},
				"json")
			});  
			//
			$(".hhsubmit").click(function () { 
				var objid = $(this).attr("date");
				var info = $(".hly"+objid).val();
					if (info == '') {
					alert("请输入内容");
					return;
				}
				var submitData = {
					nickname:'',
					fid:objid,
					info: info,
					action: "setly"
				};
				$.post('#', submitData,
				function(data) {
					if (data.success == true) {
						alert(data.msg);
						setTimeout('window.location.href=location.href',1000);
						return;
					} else {}
				},
				"json")
			});  
			//
			$(".hfinfo").click(function () { 
				var objid = $(this).attr("date");
				$(".hhly"+objid).slideToggle();
			}); 
			//
			$(".hhbt").click(function () { 
				var objid = $(this).attr("date");
				$(".hhly"+objid).slideToggle();
			});
			//
			$("#windowclosebutton").click(function () { 
				$("#windowcenter").slideUp(500);
			});
			//
			$("#alertclose").click(function () { 
				$("#windowcenter").slideUp(500);
			});
		}); 
		//
//		function alert(title){ 
//			window.scrollTo(0, -1);
//			$("#windowcenter").slideToggle("slow"); 
//			$("#txt").html(title);
//			setTimeout(function(){$("#windowcenter").slideUp(500);},4000);
//		}
		//
		$(document).ready(function(){
			$(".first1").click(function(){
				$(".ly1").slideToggle();
			});
			$(".first2").click(function(){
				$(".ly2").slideToggle();
			});
		});
	</script> 
<body>
<?php
$head_hide=1;
require("w_head.php");
?>
<div id="ly_top"><img src="images/msg.jpg" /></div>
<div class="container">
		<div class="cardexplain">
			<div class="history">
			  <div class="history-date">
			  <?php $checkList=array('店内环境','店内气氛','店内服务','员工形象','员工技术');?>
					<ul>
						<a><h2 class="first first1" style="position: relative;">点击评价</h2></a>
						<li class="nob  mb"><div class="beizhu">谢谢您留下对我们的服务评价！</div></li>
						<li class="green bounceInDown nob ly1" style="display:none">
							<form name="plform" id="plform" action="">
							<dl>
								<dt>
									<select id="clerkname" name="clerkname" class="px" >
										<option value="">请选择评价对象</option>
									<?php
										foreach($checkList as $val){ 
											echo '<option value="'.$val.'">'.$val.'</option>';
										}
									?>
									</select>
								</dt>
								<dt>
									<input name="yname" type="text" class="px" id="yname1" value="" placeholder="请输入您的姓名">
								</dt>
								<dt>
									<input name="tel" type="text" class="px" id="tel1" value="" placeholder="请输入您的联系电话">
								</dt>
								<!--<dt>
									<input name="email" type="text" class="px" id="email1" value="" placeholder="请输入您的E_mail">
								</dt>
								<dt>
									<input name="qq" type="text" class="px" id="qq1" value="" placeholder="请输入您的QQ号码">
								</dt>-->
								<dt>
									<textarea name="content" class="pxtextarea" style=" height:60px;" id="content1" placeholder="请输入评价内容"></textarea>
								</dt>
								<dt><a id="showcard1" class="submit" href="javascript:void(0)">提交评价</a></dt>
							</dl>
							</form>
						</li>			
						<?php 
							$table = 'mx_app_comment';
							$str=" and isok=1";
							if(empty($pageindex)){
								$pageindex=1;
							}
							$pagesize=intval($pagesize);
							if ($pagesize==0){
								$pagesize=8;
							}
							$order="order by adddate desc, id desc";
							$column=" * ";
							$biaoid="id";
							$list = $db->list1($pageindex, $pagesize, $table, $column, $str, $order);
							foreach($list as $k => $v){
						?>
						<li class="green bounceInDown isok_show">
							<h3><font color="green"><?php echo $v['yname'].'</font>&nbsp;对&nbsp;<font color="red">'.$v['clerkname'];?></font>的评价<span><?php echo $v['adddate']?></span><div class="clr"></div></h3>
							<dl><dt class="hfinfo" date="6765"><?php echo $v['content']?></dt></dl>
						</li>
						<?php }?>
							<li class="green bounceInDown nob ly2" style="display:none">
							<dl>
								<dt>
									<select id="clerkname2" name="clerkname2" class="px">
										<option value="">请选择评价对象</option>
									<?php
										foreach($checkList as $val){ 
											echo '<option value="'.$val.'">'.$val.'</option>';
										}
									?>
									</select>
								</dt>
								<dt>
									<input name="yname" type="text" class="px" id="yname2" value="" placeholder="请输入您的姓名">
								</dt>
								<dt>
									<input name="tel" type="text" class="px" id="tel2" value="" placeholder="请输入您的联系电话">
								</dt>
								<!--<dt>
									<input name="email" type="text" class="px" id="email2" value="" placeholder="请输入您的E_mail">
								</dt>
								<dt>
									<input name="qq" type="text" class="px" id="qq2" value="" placeholder="请输入您的QQ号码">
								</dt>-->
								<dt>
									<textarea name="content" class="pxtextarea" style=" height:60px;" id="content2" placeholder="请输入评价内容"></textarea>
								</dt>
								<dt>
									<a id="showcard2" class="submit" href="javascript:void(0)">提交评价</a>								</dt>
							</dl>
						</li>


						<a><h2 class="first first2" style="position: relative;">点击评价</h2></a>
						</ul>
			  </div>
		  </div>
			</div>
		</div>
<input type="hidden" value="1" id="pageIndex" />
<script>
$('<div><a href="javascript:void(null);" onclick="pageScroll();" id="gotop" style="background-image: url(\'/images/click_up.png\');background-repeat: no-repeat;bottom: 55px;height: 50px;position: fixed;right: 8px;text-indent: -9999px;visibility: hidden;width: 50px;z-index: 100;"></a></div>').appendTo('body');
function pageScroll(){
	document.getElementById('gotop').style.visibility='hidden';
    //把内容滚动指定的像素数（第一个参数是向右滚动的像素数，第二个参数是向下滚动的像素数）
    window.scrollBy(0,-1000);
    //延时递归调用，模拟滚动向上效果
    scrolldelay = setTimeout('pageScroll()',100);
    //获取scrollTop值，声明了DTD的标准网页取document.documentElement.scrollTop，否则取document.body.scrollTop；因为二者只有一个会生效，另一个就恒为0，所以取和值可以得到网页的真正的scrollTop值
    var sTop=document.documentElement.scrollTop+document.body.scrollTop;
    //判断当页面到达顶部，取消延时代码（否则页面滚动到顶部会无法再向下正常浏览页面）
    if(sTop==0) clearTimeout(scrolldelay);
}
window.onscroll=function(){
    if(($(document).height() - $(window).height())-$(document).scrollTop() < 100){
		//数据请求
		layout();
	}
	
    var sTop=document.documentElement.scrollTop+document.body.scrollTop;
	if(sTop>800){
	    document.getElementById('gotop').style.visibility='visible';
	}else{
	    document.getElementById('gotop').style.visibility='hidden';
	}
}
var tag = true;
/**
 * 获取信息后布局
 * @author Tony
 */
function layout(){
	var pageIndex = parseInt($('#pageIndex').val());
	if(pageIndex && tag){
		tag = false;
		var newPageIndex = pageIndex+1;
		var html = '';
		$.post('comment.php',{'type':'ajax','pageindex':pageIndex+1},function(re){
			tag = true;
			if(re.status == 1){
				$('#pageIndex').val(newPageIndex);
				var list = re.data;
				for(var i=0;i<list.length;i++){
					html += '<li class="green bounceInDown isok_show"><h3><font color="green">'+list[i].yname+'</font>&nbsp;对&nbsp;<font color="red">'+list[i].clerkname+'</font>的评价<span>'+list[i].adddate+'</span><div class="clr"></div></h3><dl><dt class="hfinfo" date="6765">'+list[i].content+'</dt></dl></li>';
				}
				$(".history-date .isok_show:last").after(html);
			}else{
				$('#pageIndex').val('0');
			}
		},'json');
	}
}
</script>
<?php require("w_foot.php")?>